#!/bin/bash
echo "mysql5.7 rpm安装"
#源码安装 这个是很稳定的版本
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
yum install -y mysql57-community-release-el7-11.noarch.rpm
yum clean all          
yum makecache          
yum install --nogpgcheck -y mysql-community-server
echo "启动MySQL服务..."
systemctl start mysqld
systemctl enable mysqld
sleep 5
temp_password=$(grep 'temporary password' /var/log/mysqld.log | awk '{print $NF}')
echo "运行MySQL安全配置..."
mysql --connect-expired-password -uroot -p"$temp_password" << EOF
SET GLOBAL validate_password_policy=LOW;
SET GLOBAL validate_password_length=4;
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
FLUSH PRIVILEGES;
EOF

echo "MySQL 5.7安装完成！"
echo "Root密码: 123456"
